package com.fausto.learnimprint.core.service.impl

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import com.fausto.learnimprint.cache.RedisCache
import com.fausto.learnimprint.cache.RedisKey
import com.fausto.learnimprint.core.mapper.AnnouncementMapper
import com.fausto.learnimprint.core.model.entity.Announcement
import com.fausto.learnimprint.core.service.IAnnouncementService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

/**
 *
 *
 * 服务实现类
 *
 *
 * @author fausto
 * @since 2022-03-28
 */
@Service
class AnnouncementServiceImpl : ServiceImpl<AnnouncementMapper, Announcement>(), IAnnouncementService {

    @Autowired
    lateinit var announcementMapper: AnnouncementMapper

    /**
     *      分页获取获取公告
     *      + AOP缓存处理
     */
    @RedisCache(key = RedisKey.ANNOUN_KEY)
    override fun getCacheAnnouncement(
        page: Int,
        showCount: Int
    ): List<Announcement> {
        return announcementMapper.selectPage(
            Page(page.toLong(), showCount.toLong()),
            QueryWrapper<Announcement>().orderByAsc("announcement_top").orderByDesc("announcement_time")
        ).records
    }
}
